/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package im.eventservice;

import im.general.AbstractListenBehaviour;
import im.messages.SubscriptionMessage;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.lang.acl.UnreadableException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author bluejack
 */
public class UnsubscribeListenBehaviour extends AbstractListenBehaviour {
    protected EventServiceAgent eventServiceAgent;
    
    public UnsubscribeListenBehaviour(EventServiceAgent eventServiceAgent) {
        this.eventServiceAgent = eventServiceAgent;
        mt = MessageTemplate.MatchEncoding("Unsubscription");
    }
    
    @Override
    protected void handleMessage(ACLMessage msg) {
        SubscriptionMessage subscriptionMessage = null;
        try {
             subscriptionMessage = (SubscriptionMessage) msg.getContentObject();
        } catch (UnreadableException ex) {
            Logger.getLogger(UnsubscribeListenBehaviour.class.getName()).log(Level.SEVERE, null, ex);
        }
        eventServiceAgent.unsubscribe(msg.getSender().getName(),subscriptionMessage);
    }
}
